/**
 * @author LYJ
 * Created by Administrator on 2018/1/6 0006.
 */

var Select = function () {

};

Select.injectData = function ($select, jsonData, value) {
    var html = "";
    html += Select.createOption(0,"--请选择--",value);
    for(var i = 0; i < jsonData.length;i++){
        var data = jsonData[i];
        html += Select.createOption(data.id,data.name,value);
    }
    $select.html(html);
};

Select.injectData = function ($select, json, keyName, ValueName, headName, value) {
    if(json == null){
        return null;
    }
    var jsonData = typeof json == "string" ? JSON.parse(json) : json;
    var html = "";
    html += Select.createOption(0,headName == null ? "--请选择--" : headName);
    for(var i = 0; i < jsonData.length;i++){
        var data = jsonData[i];
        html += Select.createOption(data[keyName],data[ValueName]);
    }
    $select.html(html);
    $select.val(value);
};


Select.createOption = function(key,name){
    return "<option value='"+key+"'>"+name+"</option>";
};


